package com.security.config;

import com.security.service.InterceptAddressService;
import com.security.service.impl.ConfigInterceptAddressServiceImpl;
import com.security.service.impl.DbInterceptAddressServiceImpl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class InterceptAddressServiceSelector {

    @Value("${security.intercept-address-source}")
    private String source;

    @Bean
    @Primary
    public InterceptAddressService interceptAddressService(
            ConfigInterceptAddressServiceImpl configService,
            DbInterceptAddressServiceImpl dbService) {
        return "db".equalsIgnoreCase(source) ? dbService : configService;
    }
}